<?
/**
 *  Wrapper function for returning rcall result for the client. The client
 *  uses javaScript.
 *
 *  Uses this to make php server scripts for handling rcall requests.
 *
 *  A sub window is used to send the call to the server. The parent of the 
 *  sub window has the function to handle the answer. It takes one parameter.
 *  It is type of string. Results are stored in that string delimited with 
 *  "/dz&" delimiter. Results can be set in array like following example shows:
 *
 *  function handleResult(answer) {    
 *      answerArr = answer.split('/dz&');
 *      aCount = answerArr.length;
 *
 *      for (c = 0; c < aCount; c++) {
 *          eval(answerArr[c]);
 *      } // for
 *  }
 *
 *  eval() function call handles the results above. Here is expected that the 
 *  result is javaScript statements.
 *
 *
 *  This code is licensed under GPL
 *  See LICENSE or www.gnu.org for more details.
 *
 *  @author Jyry Kuukkanen
 *  $Id: dzjsrcall.php 595 2006-04-03 16:00:47Z jyry $
 */

include_once("sostreams.php");
include_once("soset.php");

define(DEFAULT_HANDLER, "handleResult");

/**
 * Encode the parameter and construct the piece of javaScript that delivers
 * the result to calling client.
 *
 * PARAMS:
 *  $Result     soset containing the results. The set is encoded as follows:
 *              <key1>=<value1><result_delimiter><key2>=<value2>
 */
function returnResult($Result, $Handler = DEFAULT_HANDLER) {
    $answer = encodeRCAnswer($Result);
	$output = "<CENTER><H2>Please wait!</H2><CENTER>\n";
	$output .= "<script language='javascript'><!--\n";
	$output .= "window.opener.".$Handler."(\"". $answer ."\");\n";
	$output .= "close();\n";
	$output .= "// -->\n";
	$output .= "</script>\n";
	echo $output;
} // returnResult
?>
